home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / SSEARCH.BAS < prev    next >
BASIC Source File  |  1989-08-31  |  2KB  |  52 lines

  1. ' SEARCH.BAS
  2. ' This program reads data into three arrays and searches for a name.
  3. '   The maximum number of names that can be entered is 50; fewer
  4. '   can be entered by typing "END" for the salesperson name.
  5.  
  6. OPTION BASE 1                ' set base of all arrays to 1
  7.  
  8. DIM salesGroup$(50)          ' dimension salesGroup$ string array
  9. DIM bikesSold%(50)           ' dimension bikesSold% integer array
  10. DIM totalSales!(50)          ' dimension totalSales! floating-point array
  11.  
  12. CLS
  13.  
  14. PRINT "Follow prompts to enter bike shop data.  Type END to quit."
  15. PRINT
  16.  
  17. count% = 1                   ' initialize an array counter variable
  18.  
  19. WHILE (salesGroup$(count%) <> "END")  ' continue until name = "END"
  20.     INPUT "Enter salesperson name:  ", salesGroup$(count%)
  21.    
  22.     IF (salesGroup$(count%) <> "END") THEN
  23.         INPUT "   Bikes sold:  ", bikesSold%(count%)
  24.         INPUT "   Total sales:  $", totalSales!(count%)
  25.         PRINT
  26.         count% = count% + 1  ' increment the array counter
  27.     END IF
  28. WEND
  29.  
  30. PRINT                        ' prompt user for search string
  31. INPUT "What name would you like to search for?  ", search$
  32. PRINT
  33.  
  34. ' initialize tmp$, a formatting template for PRINT USING
  35. tmp$ = "\               \ ###          $$####.##"
  36.  
  37. ' compare each array element with search string until a match is
  38. '   found, then display the record and exit the loop; display
  39. '   message if search string is not found
  40.  
  41. FOR i% = 1 TO count% - 1     ' count% - 1 is the last array element
  42.     IF (salesGroup$(i%) = search$) THEN
  43.         PRINT "Salesperson     Bikes sold     Total sales"
  44.         PRINT "------------------------------------------"
  45.         PRINT
  46.         PRINT USING tmp$; salesGroup$(i%); bikesSold%(i%); totalSales!(i%)
  47.         EXIT FOR             ' this statement breaks out of a FOR loop
  48.     END IF
  49.     IF (i% = count% - 1) THEN PRINT "** Name not found **"
  50. NEXT i%
  51.  
  52.